package com.bayair.doctor.ui.inquiry_record;

import com.bayair.doctor.data.bean.ServerListResp;
import com.bayair.doctor.mvp.BasePresenter;
import com.bayair.doctor.mvp.annotation.InjectModel;
import com.bayair.doctor.net.RxFunction;
import com.bayair.doctor.net.RxSchedulers;
import com.bayair.doctor.ui.inquiry.InquiryModel;
import com.bayair.doctor.utils.log.KLog;
import com.tencent.qcloud.tim.uikit.modules.conversation.base.ConversationInfo;

import java.util.List;

public class InquiryRecordPresenter extends BasePresenter<InquiryRecordContract.View> implements InquiryRecordContract.Presenter {

    @InjectModel
    InquiryModel mInquiryModel;

    @Override
    public void getData() {
        mInquiryModel.getListInServer()
                .map(new RxFunction<>())
                .compose(RxSchedulers.io_main())
                .subscribe(new ObserverOnRecycler<ServerListResp>() {
                    @Override
                    public void onNext(ServerListResp patientsInServerResp) {
                        List<ServerListResp.PatientsBean> patients = patientsInServerResp.getPatients();
                        SessionDataKit.instance().setListInServer(patients);
                        loadSession();
                    }
                });
    }

    //更新IM会话
    private void loadSession() {
        SessionDataKit.instance().loadConversation(new SessionCallback() {
            @Override
            public void setList(List<ConversationInfo> data) {
                KLog.d("SessionDataKit loadConversation:"+data);
                getView().updateListData(data);
            }

            @Override
            public void update(ConversationInfo info) {
                getView().updateData(info);
            }
        });
    }


}
